<template>
    <div style="padding: 50px; color: #000!important;">
        <p style="font-size: 25px;margin-bottom: 20px">费用计算器</p>
        <Row v-if="businessType === 'finance'" style="margin-top: 50px; flex-wrap: wrap" type="flex" :gutter="50">
            <i-col span="15">
                <div style="font-weight: 700;" class="calculation-form">
                    <Form :label-width="120">
                        <!--                        <Row>-->
                        <!--                            <i-col span="24">-->
                        <!--                                <FormItem label="业务类型: ">-->
                        <!--                                    <RadioGroup v-model="businessType">-->
                        <!--                                        <Radio size="large" label="finance">金融业务</Radio>-->
                        <!--                                        <Radio size="large" label="storage">仓储业务</Radio>-->
                        <!--                                    </RadioGroup>-->
                        <!--                                </FormItem>-->
                        <!--                            </i-col>-->
                        <!--                        </Row>-->
                        <Row>
                            <i-col span="10">
                                <FormItem label="委托协议号: ">
                                    <Input v-model="formInfo.agreementNumber" size="large" disabled></Input>
                                </FormItem>
                            </i-col>
                            <i-col span="2">
                                <el-button type="primary" @click="handleagreementshow" size="mini" icon="el-icon-search"
                                           circle></el-button>
                                <el-button type="danger" @click="clear" size="mini" icon="el-icon-delete"
                                           circle></el-button>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="货款: ">
                                    <Input v-model="formInfo.paymentForGoods" size="large">
                                        <Select v-model="formInfo.currency" slot="append"
                                                style="width: 70px; background-color: #e7eaed;"
                                                @change="currencyChange">
                                            <Option value="CNY">人民币</Option>
                                            <Option value="USD">美元</Option>
                                        </Select>
                                    </Input>
                                </FormItem>
                            </i-col>
                            <i-col span="12">
                                <FormItem label="溢短比率: ">
                                    <Input v-model="formInfo.excessShortRatio" size="large" :disabled="selectagency">
                                        <span slot="append">%</span>
                                    </Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="代理费基数计算: ">
                                    <RadioGroup v-model="formInfo.calculationOfAgencyFeeBase">
                                        <Radio size="large" label="advanceMoneyForSb">垫资</Radio>
                                        <Radio size="large" label="whollyOwned">全资</Radio>
                                    </RadioGroup>
                                </FormItem>
                            </i-col>
                            <i-col span="12">
                                <FormItem label="保证金溢短: ">
                                    <RadioGroup v-model="formInfo.excessAndShortageOfGuaranteeFund">
                                        <Radio size="large" label="Y">加溢短</Radio>
                                        <Radio size="large" label="N">不加</Radio>
                                    </RadioGroup>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="保证金比率: ">
                                    <Input v-model="formInfo.marginRatio" size="large" :disabled="selectagency">
                                        <span slot="append">%</span>
                                    </Input>
                                </FormItem>
                            </i-col>
                            <i-col span="12">
                                <FormItem label="代理费比率: ">
                                    <Input v-model="formInfo.agencyFeeRatio" size="large" :disabled="selectagency">
                                        <span slot="append">%</span>
                                    </Input>
                                </FormItem>
                            </i-col>
                            <!--                            <i-col span="12">-->
                            <!--                                <FormItem label="代理费溢短: ">-->
                            <!--                                    <RadioGroup v-model="formInfo.excessOrShortageOfAgencyFee">-->
                            <!--                                        <Radio size="large" label="Y">加溢短</Radio>-->
                            <!--                                        <Radio size="large" label="N">不加</Radio>-->
                            <!--                                    </RadioGroup>-->
                            <!--                                </FormItem>-->
                            <!--                            </i-col>-->
                        </Row>
                        <Row>
                            <!--                            <i-col span="12">-->
                            <!--                                <FormItem label="代理费基数: ">-->
                            <!--                                    <Input v-model="formInfo.agencyFeeBase" size="large"></Input>-->
                            <!--                                </FormItem>-->
                            <!--                            </i-col>-->

                            <i-col span="12">
                                <FormItem label="代理天数: ">
                                    <Input v-model="formInfo.agencyDays" size="large" :disabled="selectagency">
                                        <span slot="append">天</span>
                                    </Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        <!--                        <Row>-->
                        <!--                            <i-col span="12">-->
                        <!--                                <FormItem label="代理天数: ">-->
                        <!--                                    <Input v-model="formInfo.agencyDays" size="large">-->
                        <!--                                        <span slot="append">天</span>-->
                        <!--                                    </Input>-->
                        <!--                                </FormItem>-->
                        <!--                            </i-col>-->
                        <!--                        </Row>-->
                        <Row>
                            <i-col span="12">
                                <FormItem label="">
                                    <Button size="large"
                                            style="background-color: #4f68e8;color: #fff;margin-right: 20px; width: 100%;"
                                            @click="calculation">开始计算
                                    </Button>
                                </FormItem>
                            </i-col>
                        </Row>
                    </Form>
                </div>
            </i-col>
            <i-col span="9">
                <div class="right-result">
                    <p style="font-size: 20px;font-weight: 700;margin-bottom: 40px">您的总预算: <span style="color: #f68f42;margin-left: 20px;font-size: 22px;">{{ currencySymbol }} {{ Number(dataInfo.total).toLocaleString() }}</span></p>
                    <p>货款: <span style="color: #f68f42;margin-left: 20px;font-size: 16px;">{{ currencySymbol }} {{ Number(dataInfo.paymentForGoods).toLocaleString() }}</span></p>
                    <p>保证金: <span style="color: #f68f42;margin-left: 20px;font-size: 16px;">{{ currencySymbol }} {{ Number(dataInfo.bond).toLocaleString() }}</span></p>
                    <p>代理费: <span style="color: #f68f42;margin-left: 20px;font-size: 16px;">{{ currencySymbol }} {{ Number(dataInfo.agencyFee).toLocaleString() }}</span></p>

                    <Form>
                        <FormItem label="预估汇率: " :label-width="75">
                            <Input v-model="formInfo.estimatedExchangeRate" size="large"
                                   :disabled="formInfo.currency === 'CNY'"></Input>
                        </FormItem>
                    </Form>

                    <div>
                        <Button size="large" style="background-color: #4f68e8;color: #fff;margin-right: 20px"
                                @click="addnew">新增商贸订单
                        </Button>
                        <Button size="large" style="background-color: #4f68e8;color: #fff;margin-right: 20px"
                                @click="checkRMBAmount">查看人民币金额
                        </Button>
                        <div style="color: #4f68e8; display: inline-block; cursor: pointer">
                            <a href="https://www.boc.cn/sourcedb/whpj/" target="_blank">查询汇率</a>
                        </div>
                    </div>
                </div>
            </i-col>
        </Row>


        <Row v-if="businessType === 'storage'" style="margin-top: 50px; flex-wrap: wrap" type="flex" :gutter="50">
            <i-col span="15">
                <div style="font-weight: 700;" class="calculation-form">
                    <Form :label-width="120">
                        <Row>
                            <i-col span="24">
                                <FormItem label="业务类型: ">
                                    <RadioGroup v-model="businessType">
                                        <Radio size="large" label="finance">金融业务</Radio>
                                        <Radio size="large" label="storage">仓储业务</Radio>
                                    </RadioGroup>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="仓库: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                            <i-col span="12">
                                <FormItem label="品类: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="件数: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                            <i-col span="12">
                                <FormItem label="重量: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="商品数: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                            <i-col span="12">
                                <FormItem label="托数: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="堆存天数: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                            <i-col span="12">
                                <FormItem label="箱数: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="出库车辆数: ">
                                    <Input size="large"></Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="12">
                                <FormItem label="">
                                    <Button size="large"
                                            style="background-color: #4f68e8;color: #fff;margin-right: 20px; width: 100%;">
                                        开始计算
                                    </Button>
                                </FormItem>
                            </i-col>
                        </Row>
                    </Form>
                </div>
            </i-col>
            <i-col span="9">
                <div class="right-result">
                    <p style="font-size: 20px;font-weight: 700;margin-bottom: 40px">您的总预算: </p>
                </div>
            </i-col>
        </Row>
        <el-dialog
            top="5vh"
            width="50vw"
            :visible.sync="agreementshow"
            title="代理协议列表"
            :destroy-on-close="true"
            :close-on-click-modal="false"
            @close="agreementshow = false">
            <el-table
                :data="agencyList"
                height="calc(100vh - 200px)"
                border
                size="mini"
                highlight-current-row
                sortable="custom"
                style="width: 100%; margin-top: 5px"
                oncontextmenu="return false;"
                @cell-click="handclick"
                @cell-dblclick="dbclick"
                @selection-change="selectionChange">
                <!-- <el-table-column type="selection" algin="center" width="40" /> -->
                <el-table-column type="index" align="center" label="序号" width="55"/>
                <el-table-column
                    v-for="(item, key) in column" :key="key"
                    :prop="item.key"
                    :label="item.title"
                    :min-width="item.width"
                    align="center"
                    :sortable="item.sortable"
                    :show-overflow-tooltip="true">
                    <template #default="{ row }">
                        <template v-if="item.type === 'dict'">
                            {{ $utils.handleDictData(row[item.key], dictList[item.key]) }}
                        </template>
                        <template v-else-if="item.type !== 'template'">
                            {{ $table.tableRowFormat(row, item) }}
                        </template>
                    </template>
                </el-table-column>
            </el-table>
            <template #footer>
                <el-button size="mini" type="warning" @click="agreementshow=false">取消</el-button>
                <el-button :loading="confirmLoading" size="mini" type="primary" @click="sureagreementshow">确认
                </el-button>
            </template>
        </el-dialog>
        <div>
            <el-dialog
                top="5vh"
                width="90vw"
                z-index="1000"
                :visible.sync="addnewshow"
                title="新增商贸订单"
                :destroy-on-close="true"
                :close-on-click-modal="false"
                @close="addnewshow = false">
                <div>
                    <el-steps :active="1" :align-center="true">
                        <el-step title="选择业务类型"></el-step>
                        <el-step title="填写主要信息"></el-step>
                        <el-step title="审核订单信息"></el-step>
                        <el-step title="融资放款"></el-step>
                        <el-step title="质押在库"></el-step>
                        <el-step title="填写解押信息"></el-step>
                        <el-step title="审核解押信息"></el-step>
                        <el-step title="支付解押款"></el-step>
                        <el-step title="订单完结"></el-step>
                    </el-steps>
                </div>
                <el-row style="height: 40px;line-height: 40px;">
                    <el-col :span="24" class="checkbox-label">业务类型</el-col>
                </el-row>
                <el-row style="height: 40px;line-height: 40px;">
                    <el-select
                        v-model="SelectBusinessType"
                        placeholder="请选择"
                        style="width: 100%"
                        filterable>
                        <el-option v-for="i in businessTypeList" :key="i.dictValue" :label="i.dictName"
                                   :value="i.dictValue"/>
                    </el-select>
                </el-row>

                <el-row style="height: 40px;line-height: 40px;">
                    <el-col :span="24" class="checkbox-label">运营企业</el-col>
                </el-row>
                <el-row style="height: 40px;line-height: 40px;">
                    <el-select
                        v-model="selectCompanyId"
                        placeholder="请选择"
                        style="width: 100%"
                        filterable>
                        <el-option v-for="i in customerCompanyList" :key="i.dictValue" :label="i.dictName" :value="i.dictValue" />
                    </el-select>
                </el-row>
                <template #footer>
                    <el-button size="mini" type="warning" @click="addnewshow = false">取消</el-button>
                    <el-button :loading="confirmLoading" size="mini" type="primary" @click="confirmSelectBusinessType">
                        确认
                    </el-button>
                </template>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import BigNumber from 'bignumber.js';
import { selectEntrustList } from '@/api/agencyList';
import baseCodeApi from '@/api/baseCode';

export default {
    name: 'rateQuery',
    data() {
        return {
            customerCompanyList: [],
            selectCompanyId: '',
            SelectBusinessType: 'internalAgentPurchase',
            businessTypeList: [
                {
                    dictName: '现货质押',
                    dictType: 'ORDER_BUSINESS_TYPE',
                    dictTypeName: null,
                    dictValue: 'spotPledge'
                },
                {
                    dictName: '国内代采',
                    dictType: 'ORDER_BUSINESS_TYPE',
                    dictTypeName: null,
                    dictValue: 'internalAgentPurchase'
                },
                {
                    dictName: '海外采购',
                    dictType: 'ORDER_BUSINESS_TYPE',
                    dictTypeName: null,
                    dictValue: 'abroadPurchase'
                }
            ],
            addnewshow: false,
            selectagency: false,
            selectdata: '',
            agencyList: [],
            confirmLoading: false,
            handleSelection: [],
            agreementshow: false,
            currencySymbol: '$',
            formInfo: {
                paymentForGoods: 0,
                excessShortRatio: 0,
                marginRatio: 0,
                excessAndShortageOfGuaranteeFund: 'Y',
                calculationOfAgencyFeeBase: 'advanceMoneyForSb',
                excessOrShortageOfAgencyFee: 'N',
                agencyFeeBase: 0,
                agencyFeeRatio: 0,
                agencyDays: 0,
                agreementNumber: '',
                estimatedExchangeRate: 1,
                currency: 'USD',
                agreementId: 0
            },
            dataInfo: {
                total: 0,
                paymentForGoods: 0,
                bond: 0,
                agencyFee: 0
            },
            businessType: 'finance',
            column: [

                // {
                //     key: 'customsNo',
                //     title: '审批单号',
                //     width: 220
                // },
                {
                    key: 'agreementNumber',
                    title: '代理协议号',
                    width: 180
                },

                {
                    key: 'signDate',
                    title: '签订日期',
                    width: 190,
                    type: 'date'
                },
                {
                    key: 'agreementDate',
                    title: '协议有效期',
                    width: 120
                },
                {
                    key: 'agreementEndDate',
                    title: '协议结束日期',
                    type: 'date',
                    width: 120
                },
                {
                    key: 'agreementValidDate',
                    title: '协议终止日期',
                    type: 'date',
                    width: 120
                },
                // {
                //     key: 'adventDays',
                //     title: '临期天数',
                //     width: 120,
                //     sortable: true
                // },
                {
                    key: 'earnestAmountRate',
                    title: '保证金比例（%）',
                    width: 180,
                    sortable: true
                },
                {
                    key: 'agencyFeesRate',
                    title: '代理费比例（%）',
                    width: 180,
                    sortable: true
                },
                {
                    key: 'agencyDate',
                    title: '代理期限',
                    width: 120,
                    sortable: true
                },
                {
                    key: 'moreOrLessRateEstimate',
                    title: '溢短装上浮比例（%）',
                    width: 190
                },
                {
                    key: 'agencyCost',
                    title: '协议限额（本位币）',
                    width: 190
                },
                {
                    key: 'amountCost',
                    title: '额度占用比例',
                    width: 150
                },
                {
                    key: 'grandTotalContractCost',
                    title: '累计适用合同金额（本位币）',
                    width: 220
                },
                {
                    key: 'currentAdvanceCost',
                    title: '当前垫付额（本位币）',
                    width: 190
                },

                {
                    key: 'createdDate',
                    title: '创建时间',
                    type: 'date',
                    width: 120
                },
                {
                    key: 'remark',
                    title: '备注',
                    width: 120
                }

            ]
        };
    },
    created() {
        this.getselectEntrustList();
    },
    methods: {
        calculation() {
            this.dataInfo.paymentForGoods = 0;
            this.dataInfo.bond = 0;
            this.dataInfo.agencyFee = 0;

            if (this.formInfo.currency === 'CNY') {
                this.formInfo.estimatedExchangeRate = 1;
                this.currencySymbol = '￥';
            }
            if (this.formInfo.currency === 'USD') {
                this.currencySymbol = '$';
            }
            // 货款：输入的货款金额
            if (this.formInfo.paymentForGoods) {
                this.dataInfo.paymentForGoods = this.formInfo.paymentForGoods;
            }

            /*
            保证金：
            加溢短装：货款 * (溢短装比率 + 保证金比率)
            不加溢短装：货款 * 保证金比率
            */
            if (this.formInfo.paymentForGoods && this.formInfo.marginRatio) {
                // 货款
                const paymentForGoods = new BigNumber(this.formInfo.paymentForGoods);
                // 溢短装比率
                const excessShortRatio = new BigNumber(this.formInfo.excessShortRatio).dividedBy(100);
                // 保证金比率
                const marginRatio = new BigNumber(this.formInfo.marginRatio).dividedBy(100);
                if (this.formInfo.excessAndShortageOfGuaranteeFund === 'Y') {
                    // 加溢短装
                    this.dataInfo.bond = (marginRatio.plus(excessShortRatio)).multipliedBy(paymentForGoods).toFixed(2);
                } else {
                    // 不加溢短装
                    this.dataInfo.bond = paymentForGoods.multipliedBy(marginRatio).toFixed(2);
                }
            }

            /*
            代理费：代理费基数*代理费比率／360*代理天数
            代理费基数：
            含溢短装
            全资：货款+（货款*溢短装比率）
            垫资：货款+（货款*溢短装比率）-（货款*保证金比率）
            不含溢短装
            全资：货款金额
            垫资：货款金额-（货款金额*保证金比率）
            */
            if (this.formInfo.paymentForGoods && this.formInfo.agencyFeeRatio && this.formInfo.agencyDays) {
                // 货款
                const paymentForGoods = new BigNumber(this.formInfo.paymentForGoods);
                // 代理费比率
                const agencyFeeRatio = new BigNumber(this.formInfo.agencyFeeRatio).dividedBy(100);
                // 代理天数
                const agencyDays = new BigNumber(this.formInfo.agencyDays);

                // 代理费基数
                let agencyFeeBase = new BigNumber(0);

                // 含溢短装
                if (this.formInfo.excessOrShortageOfAgencyFee === 'Y' && this.formInfo.excessShortRatio) {
                    // 溢短装比率
                    const excessShortRatio = new BigNumber(this.formInfo.excessShortRatio).dividedBy(100);
                    if (this.formInfo.calculationOfAgencyFeeBase === 'advanceMoneyForSb' && this.formInfo.marginRatio) {
                        // 垫资
                        // 保证金比率
                        const marginRatio = new BigNumber(this.formInfo.marginRatio).dividedBy(100);
                        agencyFeeBase = paymentForGoods.plus(agencyFeeBase.multipliedBy(excessShortRatio)).minus(agencyFeeBase.multipliedBy(marginRatio));
                    } else {
                        // 全资
                        agencyFeeBase = paymentForGoods.plus(paymentForGoods.multipliedBy(excessShortRatio));
                    }
                }

                // 不含溢短装
                if (this.formInfo.excessOrShortageOfAgencyFee === 'N') {
                    if (this.formInfo.calculationOfAgencyFeeBase === 'advanceMoneyForSb' && this.formInfo.marginRatio) {
                        // 垫资
                        // 保证金比率
                        const marginRatio = new BigNumber(this.formInfo.marginRatio).dividedBy(100);
                        agencyFeeBase = paymentForGoods.minus(paymentForGoods.multipliedBy(marginRatio));
                    } else {
                        // 全资
                        agencyFeeBase = paymentForGoods;
                    }
                }
                // 代理费
                this.dataInfo.agencyFee = agencyFeeBase.multipliedBy(agencyFeeRatio).dividedBy(360).multipliedBy(agencyDays).toFixed(2);
            }
            this.dataInfo.total = new BigNumber(this.dataInfo.paymentForGoods).plus(new BigNumber(this.dataInfo.agencyFee));
        },
        handleagreementshow() {
            let app = { entrustingParty: this.$utils.getUserInfo().entrustingParty };
            if (!app.entrustingParty) {
                return;
            }
            selectEntrustList(app).then(response => {
                if (response.data.returnCode === 200) {
                    this.agencyList = response.data.returnData;
                    this.agreementshow = true;
                } else {
                    this.$Message.error(response.data.returnMsg);
                }
            });
        },
        sureagreementshow() {
            this.selectagency = true;
            this.formInfo.agreementId = this.selectdata.id; //协议号id
            this.formInfo.agreementNumber = this.selectdata.agreementNumber; //协议号
            this.formInfo.marginRatio = this.selectdata.earnestAmountRate;  //保证金比例
            this.formInfo.agencyFeeRatio = this.selectdata.agencyFeesRate; //代理费
            this.formInfo.agencyDays = this.selectdata.agencyDate; //代理期限
            this.formInfo.excessShortRatio = this.selectdata.moreOrLessRateEstimate; //溢短装上浮比例
            this.agreementshow = false;
            // 保证金比例、代理费比例、代理期限、溢短装上浮比例带入预估费用指令栏位，
            // 带入信息不支持修改，根据带入信息计算预估费用。委托协议号为空时，支持手工维护计算条件。
        },
        handclick(e) {
            this.selectdata = e;
        },
        dbclick(e) {
            this.selectdata = e;
            this.selectagency = true;
            this.formInfo.agreementId = this.selectdata.id; //协议号id
            this.formInfo.agreementNumber = this.selectdata.agreementNumber; //协议号
            this.formInfo.marginRatio = this.selectdata.earnestAmountRate;  //保证金比例
            this.formInfo.agencyFeeRatio = this.selectdata.agencyFeesRate; //代理费
            this.formInfo.agencyDays = this.selectdata.agencyDate; //代理期限
            this.formInfo.excessShortRatio = this.selectdata.moreOrLessRateEstimate; //溢短装上浮比例
            this.agreementshow = false;
        },
        selectionChange(selection) {
            this.handleSelection = selection;
        },
        getselectEntrustList() {
            let app = { entrustingParty: this.$utils.getUserInfo().entrustingParty };
            if (!app.entrustingParty) {
                return;
            }
            selectEntrustList(app).then(response => {
                if (response.data.returnCode === 200) {
                    this.agencyList = response.data.returnData;
                } else {
                    this.$Message.error(response.data.returnMsg);
                }
            });
        },
        clear() {
            this.formInfo.agreementNumber = '';
        },
        checkRMBAmount() {
            if (!this.formInfo.estimatedExchangeRate) {
                this.$Message.warning('请填写预估汇率');
                return;
            }
            let paymentForGoods = new BigNumber(this.dataInfo.paymentForGoods);
            let bond = new BigNumber(this.dataInfo.bond);
            let agencyFee = new BigNumber(this.dataInfo.agencyFee);
            this.currencySymbol = '￥';

            this.dataInfo.paymentForGoods = paymentForGoods.multipliedBy(this.formInfo.estimatedExchangeRate).toFixed(2);
            this.dataInfo.bond = bond.multipliedBy(this.formInfo.estimatedExchangeRate).toFixed(2);
            this.dataInfo.agencyFee = agencyFee.multipliedBy(this.formInfo.estimatedExchangeRate).toFixed(2);
            this.dataInfo.total = new BigNumber(this.dataInfo.paymentForGoods).plus(new BigNumber(this.dataInfo.agencyFee));
        },
        currencyChange(val) {
            if (val === 'CNY') {
                this.formInfo.estimatedExchangeRate = 1;
                this.currencySymbol = '￥';
            }
            if (val === 'USD') {
                this.currencySymbol = '$';
            }
        },
        addnew() {
            baseCodeApi.getCompanyByCustomerId(this.$utils.getUserInfo().entrustingParty).then(({ data }) => {
                if (data.returnCode === 200) {
                    this.customerCompanyList = data.returnData.map(i => {
                        return {
                            dictName: i.companyName,
                            dictValue: i.id
                        };
                    });
                    if (this.customerCompanyList && this.customerCompanyList.length > 0) {
                        this.selectCompanyId = this.customerCompanyList[0].dictValue;
                    }
                    this.addnewshow = true;
                } else {
                    this.$Message.error(data.returnMsg);
                }
            }).catch(err => {
                console.log(err);
            });
        },
        confirmSelectBusinessType() {
            if (!this.selectCompanyId) {
                this.$Message.error('运营企业必填');
                return;
            }
            this.$router.push({
                path: '/platformApp/order-add',
                query: {
                    label: '新建订单',
                    businessType: this.SelectBusinessType,
                    companyId:this.selectCompanyId,
                    key: 'new',
                    disabled: true,
                    showBtn: true,
                    ViewandEdit: true,
                    saveshow: true,
                    agreementId: this.formInfo.agreementId,
                    agreementNumber: this.formInfo.agreementNumber,// 委托协议号,
                    earnestAmountRate: this.formInfo.marginRatio,  // 保证金比例,
                    agencyFeesRate: this.formInfo.agencyFeeRatio, // 代理费,
                    estimatedAgencyPeriod: this.formInfo.agencyDays, // 代理期限
                    agmtMoreOrLessRateEstimate: this.formInfo.excessShortRatio,
                    calculationOfAgencyFeeBase: this.formInfo.calculationOfAgencyFeeBase
                    //计算基数
                }
            });

        },

    },

    watch: {
        'formInfo.agreementNumber': {
            handler(val) {
                this.selectagency = val === this.selectdata.agreementNumber;
            },
            deep: true
        },
    }
};
</script>

<style scoped lang="less">
.right-result {
    border: 1px solid #e4e4e4;
    height: 100%;
    padding: 20px 50px;
    width: 100%;

    p {
        margin-bottom: 15px;
    }
}
</style>

<style lang="less">
.calculation-form, .right-result {
    font-size: 14px !important;

    .ivu-form-item-label {
        font-size: 14px !important;
        color: #000;
    }

    .ivu-checkbox-wrapper {
        font-size: 14px !important;
        color: #000;
    }

    .ivu-input, .ivu-input-group-append, .ivu-input-number-input {
        border: none !important;
        background-color: #f4f7fa;
    }

    .ivu-checkbox-checked .ivu-checkbox-inner {
        background-color: #4f68e8 !important;
    }
}
</style>
